home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / No it's NOT okay! / Patches.c < prev    next >
C/C++ Source or Header  |  2000-06-23  |  4KB  |  121 lines

  1. // Source Code generated by PatchMaker 1.0
  2. // a sick idea by Paul Baxter
  3.  
  4. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  5.     #error Sorry Can't do that
  6. #endif
  7.  
  8. #include <MixedMode.h>
  9. #include <Appearance.h>
  10. #include <SpeechSynthesis.h>
  11. #include <A4Stuff.h>
  12. #include <string.h>
  13.  
  14. // enums for routinedescriptor
  15. enum {
  16.     upp_DrawTextProcInfo = kPascalStackBased
  17.         |    STACK_ROUTINE_PARAMETER(1,kFourByteCode)
  18.         |    STACK_ROUTINE_PARAMETER(2,kTwoByteCode)
  19.         |    STACK_ROUTINE_PARAMETER(3,kTwoByteCode),
  20.     uppPatcExtraInfo
  21. };
  22.  
  23. // Function Prototypes
  24. extern pascal void my_DrawTextPatch(long param1, short param2, short param3);
  25.  
  26. // Globals to hold original routine descriptors
  27. RoutineDescriptorPtr gOriginal_DrawText = nil;
  28.  
  29. // Tell MetroWerks the procInfo for main
  30. ProcInfoType __procinfo =  kPascalStackBased;
  31. pascal void main(void)
  32. {
  33.     RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
  34.     UInt32 size;
  35.     UInt16 index;
  36.     THz theZone;
  37.  
  38.     // get globals
  39.     EnterCodeResource();
  40.     // detach ourselves
  41.     DetachResource(Get1Resource('INIT', 0));
  42.  
  43.     // make sure we are in the system heap
  44.     theZone = GetZone();
  45.     SetZone(SystemZone());
  46.     
  47.     unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
  48.  
  49.     originaldesc = NGetTrapAddress(_DrawText, (_DrawText & 0x0800) ? ToolTrap : OSTrap);
  50.     if (originaldesc != unImplimentedTrapAddr) {
  51.         if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
  52.             // Trap is 68K
  53.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 0);
  54.             // allocate new descriptor
  55.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  56.             if (!newdesc) {
  57.                 Debugger();
  58.                 return;
  59.             }
  60.             // set fields of routine decscriptor
  61.             newdesc->goMixedModeTrap = _MixedModeMagic;
  62.             newdesc->version = 7;
  63.             newdesc->routineDescriptorFlags = 0;
  64.             newdesc->reserved1 = 0;
  65.             newdesc->reserved2 = 0;
  66.             newdesc->selectorInfo = 0;
  67.             newdesc->routineCount = 0;
  68.             index = 0;
  69.             gOriginal_DrawText = originaldesc;
  70.             newdesc->routineRecords[index].procInfo = upp_DrawTextProcInfo;
  71.             newdesc->routineRecords[index].reserved1 = 0;
  72.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  73.             newdesc->routineRecords[index].routineFlags = 4;
  74.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_DrawTextPatch;
  75.             newdesc->routineRecords[index].reserved2 = 0;
  76.             newdesc->routineRecords[index].selector = 0;
  77.         }
  78.         else {
  79.             // Trap is PPC
  80.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
  81.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  82.             if (!newdesc) {
  83.                 DebugStr("\pFailed to allocate RoutineDescriptor");
  84.                 return;
  85.             }
  86.             BlockMoveData(originaldesc, newdesc, size);
  87.             gOriginal_DrawText = originaldesc;
  88.             index = 0;
  89.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_DrawTextPatch;
  90.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  91.         }
  92.         NSetTrapAddress((UniversalProcPtr) newdesc, _DrawText, (_DrawText & 0x0800) ? ToolTrap : OSTrap);
  93.     }
  94.  
  95.     // restore to original heap
  96.     SetZone(theZone);
  97.     // restore globals
  98.     ExitCodeResource();
  99. }
  100.  
  101. pascal void my_DrawTextPatch(long param1, short param2, short param3)
  102. {    
  103.     // Get globals
  104.     EnterCodeResource();
  105.     
  106.     // if the string is "OK"
  107.     if ((param3 == 2) && ((char *)param1)[param2] == 'O' && ((char *)param1)[param2+1] == 'K')
  108.     {
  109.         // replace param1 with my string
  110.         ((char *)param1)[0] = 5;
  111.         strcpy(((char *)param1)+param2, "Nooo!");
  112.         param3 = 5;
  113.     }
  114.  
  115.     CALL_THREE_PARAMETER_UPP( gOriginal_DrawText, upp_DrawTextProcInfo, param1, param2, param3);
  116.  
  117.     // Release globals
  118.     ExitCodeResource();
  119. }
  120.  
  121.